<?php

use Illuminate\Database\Seeder;
use App\Models\Category;
use Illuminate\Support\Facades\Log;

class ImportCategories extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $categories = [
        	'玄幻魔法','武侠修真','都市言情','历史军事','侦探推理','网游动漫','科幻小说','恐怖灵异','穿越架空','体育竞技'
        ];
        $i = 1;
        foreach ($categories as $category) {
        	$cg = Category::where('name', $category)->first();
        	if(is_null($cg)) {
        		$cg = Category::create([
        			'name' => $category
        		]);

        		Log::info('创建分类：' . $category);
        	}
        	if(is_null($cg->order)) {
        		$cg->order = $i;
        		$cg->save();
        	}
        	$i++;
        }
    }
}
